package com.zmhz.intercept;

import com.eova.aop.AopContext;
import com.eova.aop.MetaObjectIntercept;
import com.jfinal.plugin.activerecord.Db;

public class AdvertisingInterceptor extends MetaObjectIntercept {

	/*@Override
	public void addInit(AopContext ac) throws Exception {
		Integer userid = ac.fixed.getInt("userid");
		String sql = "select count(*) from users_info wehre userid=?";
		Integer count = Db.queryInt(sql, userid);
		
    }*/
	/**
	 * 添加用户会员信息时修改用户信息的状态为会员用户
	 */
	@Override
	public String addAfter(AopContext ac) throws Exception {
		Integer userid = ac.record.getInt("userid");
		String sql = "select usertype from frontusers  where id=?";
		Integer usertype = Db.queryInt(sql, userid);
		if(usertype == 0) {//个人用户
			sql = "update frontusers set usertype=1 where id=?";
			Db.update(sql, userid);
		}else {//企业用户
			sql = "select count(*) from corporate_info  where userid=?";
			Integer count = Db.queryInt(sql, userid);
			if(count>0) {
				sql = "update frontusers set usertype=1 where id=?";
				Db.update(sql, userid);
			}
		}
		
        return null;
    }
	/**
	 * 删除会员信息时修改用户状态为注册用户
	 */
	@Override
	public String deleteAfter(AopContext ac) throws Exception {
		Integer userid = ac.record.getInt("userid");
		String sql = "update frontusers set usertype=0 where id=?";
		Db.update(sql, userid);
		
        return null;
    }
}
